<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="用户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <a-input v-model="model.userId" placeholder="请输入用户ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="merchantId">
              <a-input v-model="model.merchantId" placeholder="请输入商户ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId" placeholder="请输入订单ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="餐品问题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="foodProblems">
              <a-input v-model="model.foodProblems" placeholder="请输入餐品问题"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="picture">
              <a-input v-model="model.picture" placeholder="请输入图片"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="意见反馈" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feedback">
              <a-input v-model="model.feedback" placeholder="请输入意见反馈"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <a-input v-model="model.state" placeholder="请输入状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processingTime">
              <j-date placeholder="请选择处理时间" v-model="model.processingTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="扣款备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deductionRemarks">
              <a-input v-model="model.deductionRemarks" placeholder="请输入扣款备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="驳回原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reasonRejection">
              <a-input v-model="model.reasonRejection" placeholder="请输入驳回原因"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="refundAmount">
              <a-input-number v-model="model.refundAmount" placeholder="请输入退款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="扣除商家金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deductMerchantAmount">
              <a-input-number v-model="model.deductMerchantAmount" placeholder="请输入扣除商家金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HcAfterSalesForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           userId: [
              { required: true, message: '请输入用户ID!'},
           ],
           merchantId: [
              { required: true, message: '请输入商户ID!'},
           ],
           orderId: [
              { required: true, message: '请输入订单ID!'},
           ],
           foodProblems: [
              { required: true, message: '请输入餐品问题!'},
           ],
           picture: [
              { required: true, message: '请输入图片!'},
           ],
           feedback: [
              { required: true, message: '请输入意见反馈!'},
           ],
           state: [
              { required: true, message: '请输入状态!'},
           ],
           deductionRemarks: [
              { required: true, message: '请输入扣款备注!'},
           ],
           reasonRejection: [
              { required: true, message: '请输入驳回原因!'},
           ],
        },
        url: {
          add: "/hc/hcAfterSales/add",
          edit: "/hc/hcAfterSales/edit",
          queryById: "/hc/hcAfterSales/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>